package st.business.tepth.business.user.busnumber.workholder.adapter;

import android.content.Context;
import android.graphics.Color;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;

import org.greenrobot.greendao.annotation.NotNull;

import java.util.List;

import st.business.tepth.business.bean.RepairTaskBean;
import st.shadow.library.ui.indicator.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import st.shadow.library.ui.indicator.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import st.shadow.library.ui.indicator.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import st.shadow.library.ui.indicator.magicindicator.buildins.commonnavigator.indicators.WrapPagerStrokeIndicator;
import st.shadow.library.ui.indicator.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;

/**
 * @author zhangyu
 * @date 2019/1/31
 */
public class TroubleAdapter extends CommonNavigatorAdapter {
    private List<RepairTaskBean.FaultPhenomenonListBean> mBeanList;
    private OnItemChooseListener mChooseListener;

    public TroubleAdapter(@NotNull List<RepairTaskBean.FaultPhenomenonListBean> list,
                          OnItemChooseListener listener) {
        mBeanList = list;
        mChooseListener = listener;
    }

    @Override
    public int getCount() {
        return mBeanList.size();
    }

    @Override
    public IPagerTitleView getTitleView(Context context, final int index) {
        SimplePagerTitleView simplePagerTitleView = new SimplePagerTitleView(context);
        simplePagerTitleView.setGravity(Gravity.CENTER);
        simplePagerTitleView.setText(mBeanList.get(index).getName());
        simplePagerTitleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 11);
        simplePagerTitleView.setNormalColor(Color.parseColor("#a0a0a0"));
        simplePagerTitleView.setSelectedColor(Color.parseColor("#dd9328"));
        simplePagerTitleView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mChooseListener != null) {
                    mChooseListener.onItemChoose(index, mBeanList.size());
                }
            }
        });
        return simplePagerTitleView;
    }

    @Override
    public IPagerIndicator getIndicator(Context context) {
        WrapPagerStrokeIndicator indicator = new WrapPagerStrokeIndicator(context);
        indicator.setFillColor(Color.parseColor("#dd9328"));
        indicator.setRoundRadius(2);
        return indicator;
    }

    public interface OnItemChooseListener {
        void onItemChoose(int index, int count);
    }
}
